package com.gurid.service.base.config;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.customizers.OpenApiCustomizer;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//@EnableSwagger2
//@EnableOpenApi //开启swagger3
public class SwaggerConfig { //Springdoc swagger3 config

    @Bean
    public GroupedOpenApi webApi(){
        return GroupedOpenApi.builder()
                .group("webApi")
                .pathsToMatch("/api/**")
                .addOpenApiCustomizer(webApiCustomizer())
                .build();
    }

    @Bean
    public GroupedOpenApi adminApi(){
        return GroupedOpenApi.builder()
                .group("adminApi")
                .pathsToMatch("/admin/**")
                .addOpenApiCustomizer(adminApiCustomizer())
                .build();
    }

    private OpenApiCustomizer webApiCustomizer() {
        return openApi -> openApi.info(
                new Info()
                        .title("网站的API文档")
                        .description("网站整体的API接口定义")
                        .version("1.0")
                        .contact(
                                new Contact()
                                        .name("Gurid")
                                        .url("https://gurid.net")
                                        .email("gurid@gmail.com"))
        );
    }
    private OpenApiCustomizer adminApiCustomizer() {
        return openApi -> openApi.info(
                new Info()
                        .title("后台管理系统的API文档")
                        .description("后台管理系统的API接口定义")
                        .version("1.0")
                        .contact(
                                new Contact()
                                        .name("Gurid")
                                        .url("https://gurid.net")
                                        .email("gurid@gmail.com"))
        );
    }

   /*@Bean
    public Docket webApiConfig() {
        return new Docket(DocumentationType.OAS_30);
    }*/

    /*@Bean
    public OpenAPI swaggerOpenApi() {
        return new OpenAPI()
                .info(new Info().title("swagger测试")
                        .description("这是一个描述")
                        .version("v1.1.1自定义的版本号"))
                .externalDocs(new ExternalDocumentation()
                        .description("外部文档")
                        //.url("http://xxx.com/xxx")
                        .url("http://springshop.wiki.github.org/docs"))
                ;
    }*/

}
